home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / cuj1008.zip / 1008016A < prev    next >
Text File  |  1992-06-12  |  642b  |  34 lines

  1.  
  2. Listing 5 -- system.c
  3.  
  4. /* system function -- UNIX version */
  5. #include <stdlib.h>
  6.  
  7.         /* UNIX system calls */
  8. int _Execl(const char *, const char *, ...);
  9. int _Fork(void);
  10. int _Wait (int *);
  11.  
  12. int (system)(const char *s)
  13.     {    /* send text to system command line processor */
  14.     if (s)
  15.         {    /* not just a test */
  16.         int pid = _Fork();
  17.  
  18.         if (pid < 0)
  19.             ;    /* fork failed */
  20.         else if (pid == 0)
  21.             {    /* continue here as child */
  22.             _Execl("/bin/sh", "sh", "-c", s, NULL);
  23.             exit(EXIT_FAILURE);
  24.             }
  25.         else    /* continue here as parent */
  26.             while (_Wait(NULL) != pid)
  27.                 ;    /* wait for child */
  28.         }
  29.     return (-1);
  30.     }
  31.  
  32.  
  33.  
  34.